package com.dps.omc.action;

import com.dps.omc.model.Agent;
import com.dps.omc.model.DbServer;
import com.dps.omc.model.Server;
import com.dps.omc.service.IAgentService;
import com.dps.omc.service.IDbServerService;
import com.dps.omc.service.IServerService;
import com.dps.omc.task.message.DesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by lip on 2016-04-25.
 */

@Controller
public class TmpScriptAction extends BaseAction{

    @Autowired
    private IAgentService agentService;
    @Autowired
    private IDbServerService dbServerService;
    @Autowired
    private IServerService serverService;

    @RequestMapping(value="/tmp/updatepass")
    @ResponseBody
    public String updatePass(String pass,HttpServletRequest request) throws Exception {

        List<Agent> agentList = agentService.findAll();
        for(Agent agent:agentList)
        {
            agent.setPassword(DesUtils.encrypt(agent.getPassword()));
            agentService.update(agent);
        }

        List<DbServer> dbServers = dbServerService.findAll();
        for(DbServer dbServer:dbServers)
        {
            dbServer.setDbPass(DesUtils.encrypt(dbServer.getDbPass()));
            dbServerService.update(dbServer);
        }

        List<Server> servers = serverService.findAll();
        for(Server server:servers)
        {
            server.setPass(DesUtils.encrypt(server.getPass()));
            serverService.update(server);
        }

        return "SUCC";
    }
}
